import 'package:flutter/material.dart';
import 'package:flutter_widget/custom/custom_appbar.dart';
import '../model/post.dart';

// ignore: must_be_immutable
class ListViewBuilderPage extends StatelessWidget {
  String name;
  ListViewBuilderPage({Key? key, required this.name}) : super(key: key);

  Widget itemBuilder(BuildContext context, int index) {
    return Container(
      child: Column(
        children: [
          Image.network(posts[index].imageUrl),
          const SizedBox(
            height: 16.0,
          ),
          Text(
            posts[index].title,
            style: const TextStyle(
              fontSize: 20.0,
            ),
          ),
          Text(
            posts[index].author,
            style: const TextStyle(
              fontSize: 16.0,
            ),
          ),
        ],
      ),
      alignment: Alignment.center,
      margin: const EdgeInsets.all(10.0),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar(name, Theme.of(context).primaryColor),
      body: Center(
        // 对于从左到右的文本（TextDirection.ltr），文本从左向右流动；
        // 对于从右到左的文本（TextDirection.rtl），文本从右向左流动。
        child: ListView.builder(
          itemBuilder: itemBuilder,
          itemCount: posts.length,
        ),
      ),
    );
  }
}
